package com.yantong.utils;

import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 获取公共配置文件
 * @author xiangyi
 *
 */
public class ConfigUtil {
	
	
	/**
	 * 获取配置信息
	 * @param plat
	 * @param type
	 * @return
	 */
	public static String getProperty(String key){
        String value = "";
        Properties props = new Properties();
        InputStream in = ConfigUtil.class.getClassLoader().getResourceAsStream("weixin4j.properties");
        try{
            props.load(in);
            value=props.getProperty(key).trim();
        }catch(IOException e){
            e.printStackTrace();
        }
        try{
            in.close();
        }catch(IOException e){
            e.printStackTrace();
        }
        return value;
    }
	
	
	/**
	 * 获取配置信息
	 * @param plat
	 * @param type
	 * @return
	 */
	public static String getPaySingleProperty(String key){
        String value = "";
        Properties props = new Properties();
        InputStream in = ConfigUtil.class.getClassLoader().getResourceAsStream("configurations.properties");
        try{
            props.load(in);
            value=props.getProperty(key).trim();
        }catch(IOException e){
            e.printStackTrace();
        }
        try{
            in.close();
        }catch(IOException e){
            e.printStackTrace();
        }
        return value;
    }
	
	
	
	
	/**
	 * 获取支付配置信息
	 * @param plat
	 * @param type
	 * @return
	 */
	public static Properties getPayProperty(){
        Properties props = new Properties();
        InputStream in = ConfigUtil.class.getClassLoader().getResourceAsStream("configurations.properties");
        try{
            props.load(in);
        }catch(IOException e){
            e.printStackTrace();
        }
        try{
            in.close();
        }catch(IOException e){
            e.printStackTrace();
        }
        return props;
    }
	
	 /**
     * 返回参数配置
     * @param str
     * @return
     */
    public static String  returnConfiguration (String str,int flag) {
    	if(StringUtils.isEmpty(str)) {
    		return null;
    	}
    	String[] configStr = str.split("other");
    	try {
    		return configStr[flag];
		} catch (Exception e) {
			return str;
		}
    }
}
